The present invention generally relates to computer system programming techniques, and more particularly, to systems and techniques by which software routines such as library functions and program subroutines pass results to calling routines.
In existing computer programming languages, routines or “methods” are defined in part by a single “return value” whose type is typically included in the definition of the method. For example, a method definition may be structured as follows:
<return-value> <method-name> (<argument>*)<exception>*
where the argument(s) and exception(s) are optional. As a specific example from the Java® programming language, a method for dividing two numbers may be written as follows:
float divideBy(float x, float y) throws DivError {                if(y = = 0) {                    throw new DivError( );                        }        return x/y;        
}
In the above example, the method divideBy generates a floating point return value equal to the quotient of the two inputs if the divisor input is not equal to zero. DivError is an exception object that is created if y is equal to zero. If this exception occurs, the execution of divideBy ceases immediately (i.e., the statement “return x/y” is not executed), and control is returned to the calling routine.
To utilize divideBy, a calling routine simply assigns its value to a variable. For example, in the following, the variable div_result obtains the result of dividing 500 by a variable z:
. . .
div_result = divideBy(500, z);
. . .
If a calling routine is to handle the exception DivError, it must include code for checking whether this exception has occurred and then performing appropriate processing:
try {                div_result = divideBy(500, z);        
} catch (DivError error) {                //processing for the divide-by-zero error        
}
While there may be multiple exception types that are generated by a method, there generally is only one return-type. If a method needs to return multiple types, it may do so by populating a separate object which a calling method accesses via a “get” method in the object. In this case, the return-type of the method is typically “void”, i.e. the method does not return a value. Alternatively, the method may return a type that is more general than the desired return types. For example, if a method returns either an integer or an integer array, it may declare its return type to be simply “Object”.